﻿using System;
using System.Collections.Generic;
using UFSoft.UBF.Util.Log;

namespace dz.inner.jky.api
{
    public class LogUtils
    {
        public void Debug(string msg)
        {
            ILogger logger = LoggerManager.GetLogger("dz.inner.jky.api");
            logger.Debug(msg);
        }

        public void Error(string msg)
        {
            ILogger logger = LoggerManager.GetLogger("dz.inner.jky.api");
            logger.Error(msg);
        }
        public void Error(Exception ex)
        {
            ILogger logger = LoggerManager.GetLogger("dz.inner.jky.api");

            logger.Error(GetAllInnerExceptionMessages(ex) + "\r\n" + ex.StackTrace);
        }
        private string GetAllInnerExceptionMessages(Exception ex)
        {
            if (ex == null)
            {
                return string.Empty;
            }

            var messages = new List<string>();

            while (ex != null)
            {
                messages.Insert(0, ex.Message); // 将当前异常的消息插入到列表的开头
                ex = ex.InnerException; // 移动到下一个InnerException
            }

            return string.Join(" -> ", messages); // 将所有消息用箭头连接起来
        }
    }
}
